package common;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @description:
 * @author: yangxuan10
 * @create: 2024-04-11 09:49
 **/
public class ListNode {

/**

    ListNode list1 = new ListNode(1);
    list1.next= new ListNode(2);

    ListNode  list2 = new ListNode(3);
    list2.next= new ListNode(4);

*/

    public int val;
    public ListNode next;

    public ListNode() {
    }

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    public static ListNode arrayConversionListNode(String strArray){
        List<Integer> array = Arrays.stream(strArray.split(",")).map(Integer::parseInt).collect(Collectors.toList());
        if (array.size() == 0) {
            return null;
        }
        ListNode list1 = new ListNode(array.get(0));
        if (array.size() ==1 ) {
            return list1;
        }
        ListNode currentNode = list1;
        for (int i = 1; i < array.size(); i++) {
            currentNode.next = new ListNode(array.get(i));
            currentNode =  currentNode.next;
        }
        return list1;
    }
}